'''
Author: Sjy
Description: combo box组件
'''
from PyQt5 import QtWidgets, QtGui, QtCore

class UiCustomComboBox(QtWidgets.QComboBox):
    def __init__(self):
        super().__init__()
    def _init(self, data):
        self.clear()
        for item in data:
            self.addItem(item.get('title', ''), item.get('value'))
    def _get(self):
        return self.currentData(QtCore.Qt.UserRole) 
    def _set(self, value):
        if value != None:
            index = self.findData(value, QtCore.Qt.UserRole)  # PySide2.QtWidgets.QComboBox.findText(text[, flags=static_cast<Qt.MatchFlags>(Qt.MatchExactly|Qt.MatchCaseSensitive)])¶
            if index != None and index >= 0:
                return self.setCurrentIndex(index)
        self.setCurrentIndex(0)